//
//  LGMemberManageCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/27.
//

#import "LGMemberManageCell.h"

@interface LGMemberManageCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UIButton *vipView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**  风险标签 */
@property (nonatomic , strong)UILabel *riskLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIButton *tipView;

@end

@implementation LGMemberManageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}


-(void)setModel:(LGPatientModel *)model{
    _model = model;
    UIImage *placeHolder = [model.gender isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:placeHolder];
    self.nameLabel.text = model.realname;
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",model.gender , model.age];
    self.contentLabel.text = model.surgery_names;
    self.vipView.hidden = (model.is_vip == YES)?NO:YES;
    [self.vipView.imageView sd_setImageWithURL:[NSURL URLWithString:model.vipicon]];
    CGFloat width = [model.realname textWidthWithFont:LGFont(16) maxHeight:viewPix(24)];
    [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width+viewPix(10)));
    }];
    if(model.is_dead == YES){
        self.nameLabel.layer.borderColor = [UIColor colorWithString:@"#333333"].CGColor;
        self.nameLabel.layer.borderWidth = 0.5;
        self.nameLabel.cornerRidus = 1;
    }else{
        self.nameLabel.layer.borderWidth = 0;
    }
    if ([model.risk_level isEqualToString:@"10"]) {
        //低风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"低风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#31A861"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#31A861"].CGColor;
        
    }else if ([model.risk_level isEqualToString:@"20"]){
        //中风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"中风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#CD8F47"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#CD8F47"].CGColor;
        
    }else if ([model.risk_level isEqualToString:@"30"]){
        //高风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"高风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#CA0505"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#CA0505"].CGColor;
    }else{
        self.riskLabel.hidden = YES;
    }
}

-(void)selectBtnAction:(UIButton *)sender{
    
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.selectBtn];
    [self.contentView addSubview:self.headPic];
    [self.headPic addSubview:self.vipView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.ageLabel];
    [self.contentView addSubview:self.riskLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.right.top.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(56)));
    }];
    [self.headPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.selectBtn.mas_right);
        make.width.height.equalTo(@(viewPix(42)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.headPic);
        make.width.equalTo(@(viewPix(24)));
        make.height.equalTo(@(viewPix(14)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(12));
        make.top.equalTo(self.headPic).offset(viewPix(8));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.riskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.ageLabel);
        make.width.equalTo(@(viewPix(34)));
        make.height.equalTo(@(viewPix(14)));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.contentView).offset(-viewPix(50));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(1));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIButton *)selectBtn{
    if(!_selectBtn){
        _selectBtn = [UIButton buttonWithImage:@"unselect24" selectImage:@"selected24"];
        [_selectBtn addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UIButton *)vipView{
    if(!_vipView){
        _vipView = [UIButton buttonWithTitle:@"会员" titleFont:LGFontWeight(9, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@""];
        [_vipView setBackgroundImage:[UIImage imageNamed:@"患者管理-标签"] forState:UIControlStateNormal];
        _vipView.hidden = YES;
    }
    return _vipView;
}

-(UIButton *)tipView{
    if(!_tipView){
        _tipView = [UIButton buttonWithImage:@"grayTip16" selectImage:@"grayTip16"];
        _tipView.userInteractionEnabled = NO;
    }
    return _tipView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"姓名" colorString:@"#17191D" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UILabel *)riskLabel{
    if(!_riskLabel){
        _riskLabel = [UILabel lableWithText:@"" colorString:@"#31A861" textFont:LGFont(10) textAlignment:NSTextAlignmentCenter lines:1];
        _riskLabel.layer.borderWidth = 0.5;
        _riskLabel.cornerRidus = 2;
    }
    return _riskLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithString:@"EFEFEF"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
